#include "model.h"

/////////////////////////////////////////////////////////////////////////////////
///								    StringParams							 ////	
/////////////////////////////////////////////////////////////////////////////////
DaoModel::StringParams::StringParams() {
	this->m_id = IdProducer::nextId();
	this->m_name = "";
	this->m_lastUseTime = QDateTime::currentDateTime();
}

void DaoModel::StringParams::setId(qint64 id) {
	m_id = id;
}

void DaoModel::StringParams::setName(QString name) {
	m_name = name;
}

void DaoModel::StringParams::setLastUseTime(qint64 time) {
	try {
		this->m_lastUseTime = QDateTime::fromMSecsSinceEpoch(time);
	} catch (const std::exception& e) {
		qWarning() << e.what();
	}
}

void DaoModel::StringParams::setLastUseTime(QString& time, QString& format) {
	try {
		this->m_lastUseTime = QDateTime::fromString(time, format);
	} catch (const std::exception& e) {
		qWarning() << e.what();
	}
}


/////////////////////////////////////////////////////////////////////////////////
///								    TestData								 ////	
/////////////////////////////////////////////////////////////////////////////////

DaoModel::TestData::TestData() { 
	//编号 
	m_id = IdProducer::nextId(); 
	//检测时间
	m_createTime = QDateTime::currentDateTime();
}
DaoModel::TestData::TestData(QString tester, QString schedule, QString brand, QString num,DetectResult& data) :
	m_tester(tester), m_schedule(schedule), m_brand(brand), m_num(num){

	//数据库主键
	m_id = IdProducer::nextId();

    //薄膜最高高度
	m_maxHeight = data.maxHeight;

	//薄膜最低高度
	m_minHeight = data.minHeight;

	//薄膜平均高度
	m_meanHeight = data.meanHeight;

	//薄膜高度数据标准方差
	m_heightSD = data.heightSD;

	//薄膜异常区域-荷叶边
	m_abnormalArea = data.abnormalArea;
}

void DaoModel::TestData::setId(qint64 id) { m_id = id; }

void DaoModel::TestData::setBrand(QString val) {
	m_brand = val;
};

void DaoModel::TestData::setTester(QString val) {
	m_tester = val;
};

void DaoModel::TestData::setSchedule(QString val) {
	m_schedule = val;
};

void DaoModel::TestData::setNum(QString num) { m_num = num; }

//void DaoModel::TestData::setName(QString name) {
//	m_name = name;
//}

void DaoModel::TestData::setMaxHeight(double maxHeight)
{
	m_maxHeight = maxHeight;
}

void DaoModel::TestData::setMinHeight(double minHeight)
{
	m_minHeight=minHeight;
}

void DaoModel::TestData::setMeanHeight(double meanHeight)
{
	m_meanHeight = meanHeight;
}

void DaoModel::TestData::setHeightSD(double heightSD)
{
	m_heightSD = heightSD;
}

void DaoModel::TestData::setAbnormalArea(double abnormalArea)
{
	m_abnormalArea = abnormalArea;
}


//void DaoModel::TestData::setArea(double area) { m_area = area; }
//
//void DaoModel::TestData::setWarningArea(double area) { m_warningArea = area; }
//
//void DaoModel::TestData::setLineWidth(QString val) { m_lineWidth = val; }
//
//void DaoModel::TestData::setLineWidth(vector<double>& valList) {
//	m_lineWidth.clear();
//	if (valList.size() > 0) {
//		QStringList strList;
//		for (double val : valList) {
//			strList.push_back(QString::number(val, 'f', Configuration::getInstance().accuracy.value));
//		}
//		m_lineWidth = strList.join("/");
//	}
//}
//
//void DaoModel::TestData::setTextCount(vector<int>& valList) {
//	m_textCount = 0;
//	for (int val : valList) {
//		if (val > 0) {
//			m_textCount += val;
//		}
//	}
//}
//
//void DaoModel::TestData::setTextCount(int val) {
//	if (val > 0) {
//		m_textCount = val;
//	}
//}
//
//void DaoModel::TestData::setTextHeight(QString val) { m_textHeight = val; }
//
//void DaoModel::TestData::setTextHeight(vector<double>& valList) {
//	m_textHeight.clear();
//	if (valList.size() > 0) {
//		QStringList strList;
//		for (double val : valList) {
//			strList.push_back(QString::number(val, 'f', Configuration::getInstance().accuracy.value));
//		}
//		m_textHeight = strList.join("/");
//	}
//};

//void DaoModel::TestData::setTextArea(double val) { m_textArea = val; }

void DaoModel::TestData::setCreateTime(QDateTime& time) { m_createTime = time; }


const QString DaoModel::TestData::toString() const { 
	QStringList val;
	val << "{";
	val << QString("id: %1,").arg(m_id);
	val << QString("tester: %1,").arg(m_tester);
	val << QString("schedule: %1,").arg(m_schedule);
	val << QString("brand: %1,").arg(m_brand);
	val << QString("num: %1,").arg(m_num);
	val << QString("maxHeight: %1,").arg(m_maxHeight);
	val << QString("minHeihgt: %1,").arg(m_minHeight);
	val << QString("meanHeight: %1,").arg(m_meanHeight);
	val << QString("heightSD: %1,").arg(m_heightSD);
	val << QString("abnormalArea: %1,").arg(m_abnormalArea);
	val << QString("createTime: %1,").arg(m_createTime.toString("yyyy-MM-dd HH:mm:ss"));
	val << "}";
	return val.join(" ");
}


